import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";
import { MapAreaEntity } from "./map-area.entity";

@Entity("character_locations")
@ManualTimestamp()
export class CharacterLocationEntity {
  @PrimaryGeneratedColumn({ comment: "主键ID" })
  id!: number;

  @Column({ name: "character_id", type: "bigint", comment: "角色ID" })
  characterId!: number;

  @Column({
    name: "area_id",
    type: "int",
    default: 2,
    comment: "当前区域ID（默认2-新手村）" })
  areaId!: number;

  @Column({ name: "last_move_time", type: "datetime", comment: "最后移动时间" })
  lastMoveTime!: Date;

  @Column({
    name: "is_online",
    type: "tinyint",
    default: 1,
    comment: "是否在线（1:在线, 0:离线）" })
  isOnline!: number;

  @Column({
    name: "last_online_time",
    type: "datetime",
    comment: "最后在线时间" })
  lastOnlineTime!: Date;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => CharacterEntity, (character) => character.location)
  @JoinColumn({ name: "character_id" })
  character!: CharacterEntity;

  @ManyToOne(() => MapAreaEntity)
  @JoinColumn({ name: "area_id" })
  area!: MapAreaEntity;
}
